<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>更新用户</title>
<link href="static/css/style.css" rel="stylesheet" type="text/css" />
<link href="static/css/select.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="static/js/jquery.js"></script>
<script type="text/javascript" src="static/js/jquery.idTabs.min.js"></script>
<script type="text/javascript" src="static/js/select-ui.min.js"></script>
<script type="text/javascript" src="static/editor/kindeditor.js"></script>

<script type="text/javascript">
    KE.show({
        id : 'content7',
        cssPath : './index.css'
    });
  </script>
  
<script type="text/javascript">
$(document).ready(function(e) {
	
	var msg = '${requestScope.msg}';
	if(msg!=null&&msg!=''){
		alert(msg);
	}
	
	
    $(".select1").uedSelect({
		width : 345			  
	});
	$(".select2").uedSelect({
		width : 167  
	});
	$(".select3").uedSelect({
		width : 100
	});
	
	$(".dfinput").each(function(){
		$(this).change(function(){
			check();
		});
	});
	
	var result = '${result.msg}';
	if(''!==result){
		alert(result);
	}
	
	function check(){
		var dfinput = $(".dfinput");
		for(var i=0;i<dfinput.length;i++){
			var val = $(dfinput[i]).val();
			if(!val){
				$("#submit_but").css("background", "rgb(169,169,169)");
				return false;
			}
		}
		$("#submit_but").removeAttr("disabled");
		$("#submit_but").css("background", "rgb(62,175,224)");
	}
	
	$("#userName").focusout(function(){
		$.ajax({
			url: 'User_checkName.action',
		    type: 'POST', //GET
		    async: false,    //或false,是否异步
		    data:{
		    	'user.userName':$("#userName").val()
		    },
		    dataType: 'json',  //返回的数据格式：json/xml/html/script/jsonp/text
		    success: function(data){
		        if(data.code==0){
		        	alert(data.msg);
		        }
		        
		    },
		    error: function(XMLHttpRequest, textStatus, errorThrown){
		    }
		});
	});
	
	
	
	$("#department").change(function(){
		var departmentID = $("#department").val();
		$.ajax({
			url: 'User_findLaboratoryByDepartmentID.action',
		    type: 'POST', //GET
		    async: false,    //或false,是否异步
		    data:{
		    	'departmentID':departmentID
		    },
		    dataType: 'json',  //返回的数据格式：json/xml/html/script/jsonp/text
		    success: function(data){
		        if(data.code==0){
		        	alert(data.msg);
		        }else{
		        	console.log(data.data);
		        	$("#lab_td_list").html("");
		        	$.each(data.data, function(index, lab){
		        		var td = "<td><input name='user_lab.makeNew["+index+"].id' checkboxType='lab' type='checkbox' value='"+lab.id+"' />&nbsp;"+lab.labName+"</td><td>&nbsp;&nbsp;</td>";
		        		$("#lab_td_list").append(td);
		        	});
		        }
		        
		    },
		    error: function(XMLHttpRequest, textStatus, errorThrown){
		    	console.log(errorThrown);
		    }
		});
	});
	
});
function checkForm(){
	if($("#password").val()!=$("#rePassword").val()){
		alert("密码与确认密码不符");
		return false;
	}
	
	var len = $("input[checkboxType=role]:checkbox:checked").length;
	if(len==0){
		alert("至少选择一个角色！");
		return false;
	}
	
	if($("#department").val()==-1){
		alert("请选择部门！");
		return false;
	}
	
	
	var len = $("input[checkboxType=lab]:checkbox:checked").length;
	if(len==0){
		alert("至少选择一个实验室！");
		return false;
	}
	
	return true;
}
</script>
</head>

<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="PageFrame_index.action">首页</a></li>
    </ul>
    </div>
    
    <div class="formbody">
    
    
    <div id="usual1" class="usual"> 
    
    <div class="itab">
  	<ul> 
    <li><a href="#tab1" class="selected">修改用户</a></li> 
  	</ul>
    </div> 
    
    <form name="addRoleForm" action="User_doUpdate.action?user.id=${user.id}" onsubmit="return checkForm()" method="post">
  	<div id="tab1" class="tabson">
    
    <div class="formtext">Hi，<b>${user.userName}</b>，欢迎您试用修改用户功能！</div>
    
    <ul class="forminfo">
    <li><label>用户名称<b>*</b></label><input id="userName" name="user.userName" type="text" class="dfinput" value="${requestScope.user.userName}"  style="width:250px;"/></li>
   	<li><label>密       码<b>*</b></label><input id="password" name="user.userPassword" type="password" class="dfinput" value="${requestScope.user.userPassword}"  style="width:250px;"/></li>
 	<li><label>确认密码<b>*</b></label><input id="rePassword" name="rePassword" type="password" class="dfinput" value="${requestScope.user.userPassword}"  style="width:250px;"/></li>
 	<li><label>联系电话<b>*</b></label><input name="user.telephone" type="text" class="dfinput" value="${requestScope.user.telephone}"  style="width:250px;"/></li>
        <li>
    <label>角色<b>*</b></label>
    <!-- Set必须要使用makeNew运算符，这样ognl才能帮我创建新的对象，否则roles会为空 。
    	如果集合类型是List，直接name="roles[0].id"就可以。
    	在Class-conversion.properties文件中加上KeyProperty_orders=id，这是封装Set时必须的
     -->
    <table>
    <tbody>
    <c:set var="i" value="0" />
    <c:forEach items="${requestScope.user.user_role}" var="role" varStatus="status"> 
		<td><input name="roles.makeNew[${i}].id" checked="checked" checkboxType='role' type="checkbox" value="${role.id}" /></td><td>&nbsp;${role.roleDesc}&nbsp;&nbsp;</td>
    	<c:set var="i" value="${i+1}" />
    </c:forEach>
    
    <c:forEach items="${list}" var="role" varStatus="status"> 
		<td><input name="roles.makeNew[${i}].id"  type="checkbox" checkboxType='role' value="${role.id}" /></td><td>&nbsp;${role.roleDesc}&nbsp;&nbsp;</td>
    	<c:set var="i" value="${i+1}" />
    </c:forEach>
    </tbody>
    </table>
    </li>
    
     <li>
      <label>选择部门<b>*</b></label>
 	   <div class="vocation">
    	<!-- 如果使用 select1 可能导致取不到值-->
    	<select id="department" name="test" class="select2">
    	<option value="-1" selected="selected" >--请选择部门--</option>
    	<c:forEach items="${departmentList}" var="department">
    		<option value="${department.id}">${department.deptName} </option>
    	</c:forEach>
	    </select>
	  </div> 
     </li>
   	
   	<li>
    <label>实验室<b>*</b></label>
    <!-- Set必须要使用makeNew运算符，这样ognl才能帮我创建新的对象，否则roles会为空 。
    	如果集合类型是List，直接name="roles[0].id"就可以。
    	在Class-conversion.properties文件中加上KeyProperty_orders=id，这是封装Set时必须的
     -->
    <table>
    <tbody>
    <tr id="lab_td_list"  style="height: 34px">
    
    </tr>   
    </tbody>
    </table>
    </li>
    
   	
    <li><label>&nbsp;</label><input name="" id="submit_but" type="submit" class="btn" value="马上更新"/></li>
    </ul>
    
    </div> 
    </form>
    
	</div> 
 
	<script type="text/javascript"> 
      $("#usual1 ul").idTabs(); 
    </script>
    
    <script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');
	</script>
    
    
    </div>


</body>

</html>
